package com.hntxk.cqzd.export.controller;/**
 * @ClassName: ${user}
 * @Author:liuqing
 * @Description
 * @Date: Created in 15:29 2020/10/14
 * @Modified By:
 */

import com.alibaba.fastjson.JSON;
import com.hntxk.core.framework.action.BaseController;
import com.hntxk.cqzd.consultation.entity.TblDibInfo;
import com.hntxk.cqzd.consultation.service.DibInfoService;
import com.hntxk.cqzd.diacrisis.entity.TblDiacrisisInfo;
import com.hntxk.cqzd.diacrisis.service.DiacrisisInfoService;
import com.hntxk.cqzd.export.model.ExcelExportConstant;
import com.hntxk.cqzd.export.util.ExcelUtil;
import com.hntxk.cqzd.flup.entity.FlupInfo;
import com.hntxk.cqzd.flup.service.FlupInfoService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName HistoryQueryController
 * @description 历史查询模块导出
 * @Author Liuqing
 * @Date 2020/10/14 15:29
 * @Version 1.0
 */
@Api(value="历史查询导出", tags={"[SP]历史查询导出"})
@Controller
@RequestMapping("cqzd/historyQuery")
@Slf4j
public class HistoryQueryController extends BaseController {
    //
    private final DiacrisisInfoService diacrisisInfoService;

    private final DibInfoService dibInfoService;

    private final FlupInfoService flupInfoService;

    @Autowired
    public HistoryQueryController(@Qualifier("diacInfoService") DiacrisisInfoService diacrisisInfoService, @Qualifier("dibInfoManageService")DibInfoService dibInfoService, @Qualifier("flupInfoManageService")FlupInfoService flupInfoService) {
        this.diacrisisInfoService = diacrisisInfoService;
        this.dibInfoService = dibInfoService;
        this.flupInfoService = flupInfoService;
    }


    @ResponseBody
    @RequestMapping(value = "/diagnosisInfo" ,method = RequestMethod.GET)
    public String diagnosisInfo(@ModelAttribute TblDiacrisisInfo model, HttpServletResponse response){
        List<TblDiacrisisInfo> diagnosisInfoExports = diacrisisInfoService.query(model);

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExcelUtil.generateExcelSaveLocal(diagnosisInfoExports,
                ExcelExportConstant.DIAGNOSIS_INFO_TITLE,
                ExcelExportConstant.DIAGNOSIS_INFO_FIELD,
                response,formatter.format(currentTime).replace(" ","-").replace(":","-"));
        return JSON.toJSONString("success");
    }



    @ResponseBody
    @RequestMapping(value = "/consultationInfo" ,method = RequestMethod.GET)
    public String consultationInfo(@ModelAttribute TblDibInfo model, HttpServletResponse response){
        List<TblDibInfo> consultationInfoExports = dibInfoService.query(model);

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExcelUtil.generateExcelSaveLocal(consultationInfoExports,
                ExcelExportConstant.CONSULTATION_INFO_TITLE,
                ExcelExportConstant.CONSULTATION_INFO_FIELD,
                response,formatter.format(currentTime).replace(" ","-").replace(":","-"));
        return JSON.toJSONString("success");
    }


    @ResponseBody
    @RequestMapping(value = "/followUpInfo" ,method = RequestMethod.GET)
    public String followUpInfo(@ModelAttribute FlupInfo model, HttpServletResponse response){
        List<FlupInfo> followUpInfoExports = flupInfoService.query(model);

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExcelUtil.generateExcelSaveLocal(followUpInfoExports,
                ExcelExportConstant.FOLLOWUP_INFO_TITLE,
                ExcelExportConstant.FOLLOWUP_INFO_FIELD,
                response,formatter.format(currentTime).replace(" ","-").replace(":","-"));
        return JSON.toJSONString("success");
    }


}
